<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>星际数字跳跃 - 大数认知教学游戏</title>
  <meta name="description" content="专为四年级学生设计的大数认知教学游戏，包含黑洞纠错台、单位跃迁台、星际对比跳三种模式">
  <meta name="keywords" content="数学游戏,大数认知,四年级,教学游戏,数字读写">
  
  <!-- PWA支持 -->
  <link rel="manifest" href="./manifest.json">
  <meta name="theme-color" content="#1a1a2e">
  
  <!-- 图标 -->
  <link rel="icon" type="image/x-icon" href="./favicon.ico">
  <link rel="apple-touch-icon" href="./icon-192.png">
  
  <!-- 预加载关键资源 -->
  <link rel="preload" href="./assets/phaser.min.js" as="script">
  
  <style>
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }
    
    body {
      background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
      font-family: 'Microsoft YaHei', Arial, sans-serif;
      overflow: hidden;
      user-select: none;
    }
    
    #game-container {
      width: 100vw;
      height: 100vh;
      display: flex;
      justify-content: center;
      align-items: center;
    }
    
    #loading {
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      z-index: 1000;
      color: white;
    }
    
    .loading-spinner {
      width: 50px;
      height: 50px;
      border: 3px solid rgba(255, 255, 255, 0.3);
      border-top: 3px solid #FDE047;
      border-radius: 50%;
      animation: spin 1s linear infinite;
      margin-bottom: 20px;
    }
    
    @keyframes spin {
      0% { transform: rotate(0deg); }
      100% { transform: rotate(360deg); }
    }
    
    .loading-text {
      font-size: 18px;
      margin-bottom: 10px;
    }
    
    .loading-progress {
      width: 300px;
      height: 4px;
      background: rgba(255, 255, 255, 0.2);
      border-radius: 2px;
      overflow: hidden;
    }
    
    .loading-bar {
      height: 100%;
      background: linear-gradient(90deg, #FDE047, #F59E0B);
      width: 0%;
      transition: width 0.3s ease;
    }
    
    /* 响应式设计 */
    @media (max-width: 768px) {
      body {
        font-size: 14px;
      }
    }
    
    /* 全屏按钮样式 */
    #fullscreen-btn {
      position: fixed;
      top: 20px;
      right: 20px;
      background: rgba(0, 0, 0, 0.7);
      color: white;
      border: none;
      padding: 10px 15px;
      border-radius: 5px;
      cursor: pointer;
      font-size: 14px;
      z-index: 100;
      transition: background 0.3s;
    }
    
    #fullscreen-btn:hover {
      background: rgba(0, 0, 0, 0.9);
    }
  </style>
</head>
<body>
  <!-- 加载界面 -->
  <div id="loading">
    <div class="loading-spinner"></div>
    <div class="loading-text">正在加载星际数字跳跃...</div>
    <div class="loading-progress">
      <div class="loading-bar" id="loading-bar"></div>
    </div>
  </div>
  
  <!-- 全屏按钮 -->
  <button id="fullscreen-btn" onclick="toggleFullscreen()">全屏</button>
  
  <!-- 游戏容器 -->
  <div id="game-container"></div>
  
  <!-- 加载Phaser -->
  <script src="./assets/phaser.min.js"></script>
  
  <!-- 游戏脚本 -->
  <script type="module">
    // 模拟加载进度
    let progress = 0;
    const loadingBar = document.getElementById('loading-bar');
    const loadingElement = document.getElementById('loading');
    
    const updateProgress = () => {
      progress += Math.random() * 15;
      if (progress > 100) progress = 100;
      loadingBar.style.width = progress + '%';
      
      if (progress >= 100) {
        setTimeout(() => {
          loadingElement.style.opacity = '0';
          setTimeout(() => {
            loadingElement.style.display = 'none';
          }, 500);
        }, 500);
      } else {
        setTimeout(updateProgress, 100 + Math.random() * 200);
      }
    };
    
    updateProgress();
    
    // 全屏功能
    window.toggleFullscreen = () => {
      if (!document.fullscreenElement) {
        document.documentElement.requestFullscreen();
      } else {
        document.exitFullscreen();
      }
    };
    
    // PWA安装提示
    let deferredPrompt;
    window.addEventListener('beforeinstallprompt', (e) => {
      e.preventDefault();
      deferredPrompt = e;
      
      // 显示安装提示
      const installBtn = document.createElement('button');
      installBtn.textContent = '安装到桌面';
      installBtn.style.cssText = `
        position: fixed;
        bottom: 20px;
        right: 20px;
        background: #FDE047;
        color: #1a1a2e;
        border: none;
        padding: 12px 20px;
        border-radius: 25px;
        cursor: pointer;
        font-weight: bold;
        z-index: 100;
        box-shadow: 0 4px 12px rgba(0,0,0,0.3);
      `;
      
      installBtn.onclick = async () => {
        if (deferredPrompt) {
          deferredPrompt.prompt();
          const { outcome } = await deferredPrompt.userChoice;
          if (outcome === 'accepted') {
            installBtn.remove();
          }
          deferredPrompt = null;
        }
      };
      
      document.body.appendChild(installBtn);
      
      // 5秒后自动隐藏
      setTimeout(() => {
        if (installBtn.parentNode) {
          installBtn.remove();
        }
      }, 10000);
    });
    
    // 加载游戏
    import('./js/main.js');
  </script>
</body>
</html>
